import requests

from common.config import getconf
from tests.new_rypark_background.get_cookie import internal_token


class ParkingGate:
    # =====================车道管理=====================

    def create_parking_gate(self, env, type=1,name="自动化测试新建进口"):
        """创建车道"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGate/create"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
              "name":name,
              "type": type,  #进口-1 出口-2
              "parkingLotId": getconf(env, "parking_lot_id"),
              "parkingGarageId": getconf(env, "parking_garage_id"),
              "parkingSentryBoxId": getconf(env, "parkingSentryBoxId")
        }
        return requests.post(url, headers=headers, json=dict).json()

    def query_parking_gate_list(self, env, params={}):
        """车道列表"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGate/list/page"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = { "name": "", "type": "", "parkingLotId": "", "parkingGarageId": "", "parkingSentryBoxId": "", "status": "", "current": 1, "size": 10 }
        keys = dict.keys()
        for key in keys:
            if key in params.keys():
                dict[key] = params[key]
        return requests.post(url, headers=headers, json=dict).json()

    def update_parking_gate(self, env, id="",type=1,name=""):
        """更新车道"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGate/update"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "id":id,
            "name": name,
            "type": type   # 进口-1 出口-2
        }
        return requests.post(url, headers=headers, json=dict).json()

    def update_parking_gate_status(self, env, id="",status=9):
        """启用/停用车道"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGate/updateStatus"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "id":id,
            "status": status   # 停用-9 启用-1
        }
        return requests.post(url, headers=headers, json=dict).json()

